/*
 * TileLayer.cpp
 *
 *  Created on: 10/11/2011
 *      Author: Tales
 */

#include "TileLayer.hpp"
#include "../video/Tileset.hpp"
#include "../video/Screen.hpp"
#include "../framework/DrawEvent.hpp"
#include "../framework/Scene2d.hpp"

namespace yep
{

TileLayer::TileLayer()
{

}

TileLayer::TileLayer(Tileset & tileset, unsigned mapWidth, unsigned mapHeight) :
		_tilemap(tileset, mapWidth, mapHeight)
{
}

TileLayer::TileLayer(const initializer_list<int> & list) :
		_tilemap(list)
{
}

TileLayer::~TileLayer()
{
}

double TileLayer::getDepth()
{
	return _depth;
}

Vector2 TileLayer::getPosition() const
{
	return _position;
}

Vector2 TileLayer::getSize() const
{
	return _size;
}

Tilemap TileLayer::getTilemap() const
{
	return _tilemap;
}

void TileLayer::setDepth(double depth)
{
	_depth = depth;
}

void TileLayer::setPosition(Vector2 position)
{
	_position = position;
}

void TileLayer::setSize(Vector2 size)
{
	_size = size;
}

void TileLayer::setTilemap(Tilemap tilemap)
{
	_tilemap = tilemap;
}

void TileLayer::evDestroy(Event & event)
{
	delete this;
}

void TileLayer::evCreate(Event & event)
{
	event.getScene().handleDraw(*this);
	if (_size == Vector2(0, 0))
	{
		Tileset &tileset_ = getTileset();
		_size = Vector2(getMapWidth() * tileset_.getTileWidth(), getMapHeight() * tileset_.getTileHeight());
	}
}

void TileLayer::evDraw(DrawEvent & drawEvent)
{
	_tilemap.draw(drawEvent.getScreen(), _position - drawEvent.getViewPosition());
}

} /* namespace yep */
